<?php

namespace App\Admin\Controllers;

use App\Models\SwtTransferOrder;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SwtTransferOrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(SwtTransferOrder::with(['seller']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('order_sn');
            $grid->column('seller.realname','转让方');
            $grid->column('num');
            $grid->column('price');
            $grid->column('total');
            $grid->column('fee');
            $grid->column('pay_type')->using(['微信','支付宝'])->label(['success','info']);
            $grid->column('pay_name');
            $grid->column('pay_no');
            $grid->column('pay_code') -> image(config('app.url'),50,50);
            $grid->column('status')->using(['待下单','已锁定','已支付','已取消','已完成'])->label(['info','purple','warning','danger','success']);
            $grid->column('sign_status','审核状态')->using(['待审核','通过','驳回'])->label(['danger', 'info','success']);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid -> disableCreateButton();

            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('status', '状态', ['待下单','已锁定','已支付','已取消','已完成']);
                $selector->select('sign_status', '审核状态', ['待审核','通过','驳回']);
            });

            $grid -> actions(function (Grid\Displayers\Actions $actions) {
               $actions -> disableEdit();
               $actions -> disableDelete();
               $actions -> quickEdit($actions -> row -> sign_status == 0 && $actions -> row -> status != 3);
            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtTransferOrder(), function (Show $show) {
            $show->field('id');
            $show->field('order_sn');
            $show->field('seller_id');
            $show->field('buyer_id');
            $show->field('num');
            $show->field('price');
            $show->field('total');
            $show->field('fee');
            $show->field('pay_type');
            $show->field('pay_name');
            $show->field('pay_no');
            $show->field('pay_code');
            $show->field('status');
            $show->field('pay_status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(SwtTransferOrder::with(['seller']), function (Form $form) {
            $form->display('id');
            $form->display('order_sn');
            $form->display('seller.realname','转让方');
            $form->display('num');
            $form->display('fee');
            $form->radio('sign_status','审核状态') -> options([ 1 => '通过', 2 => '驳回']);
        });
    }
}
